local skel = fk.CreateSkill {
  name = "lb__hecai",
}

Fk:loadTranslationTable {
  ["lb__hecai"] = "和财",
  [":lb__hecai"] = "每回合限一次，当其他角色使用基本牌或普通锦囊牌指定唯一目标时，你可以弃置一张与之花色相同的牌为之“助战 → 目标+1”。此牌结算后，你与其各摸此牌造成的伤害数张牌。",

  ["#lb__hecai"] = "和财：你可以弃置一张 %arg牌为 %src 的 %arg2 “助战 → 目标+1”",

  ["$lb__hecai1"] = "客人嘛，岂有不招待的道理。 ",
  ["$lb__hecai2"] = "要不咱们还是以和为贵？",
}

skel:addEffect(fk.TargetSpecifying, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and player:usedSkillTimes(skel.name) < 1 and not player:isNude()
        and player ~= target and data:isOnlyTarget(data.to) and not data.cancelled
        and (data.card.type == Card.TypeBasic or data.card:isCommonTrick())
  end,
  on_cost = function(self, event, target, player, data)
    local cards = player.room:askToDiscard(player, {
      min_num = 1,
      max_num = 1,
      skill_name = skel.name,
      cancelable = true,
      include_equip = true,
      pattern = ".|.|" .. data.card:getSuitString(),
      prompt = "#lb__hecai:" .. target.id .. "::" .. data.card:getSuitString(true) .. ":" .. data.card:toLogString(),
      skip = true,
    })
    if #cards > 0 then
      event:setCostData(self, { cards = cards })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(event:getCostData(self).cards, skel.name, player)
    data.extra_data = data.extra_data or {}
    data.extra_data.lb__hecai = player
    if target:isAlive() and #data:getExtraTargets() > 0 then
      local to = room:askToChoosePlayers(target, {
        min_num = 1,
        max_num = 1,
        targets = data:getExtraTargets(),
        skill_name = skel.name,
        prompt = "#variation_addtarget:::" .. data.card:toLogString(),
        cancelable = true,
      })
      if #to > 0 then
        data:addTarget(to[1])
      end
    end
  end,
})

skel:addEffect(fk.CardUseFinished, {
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    if data.extra_data and data.extra_data.lb__hecai and player == data.extra_data.lb__hecai
        and data.damageDealt and (target:isAlive() or data.extra_data.lb__hecai:isAlive()) then
      local num = 0
      for _, damage in pairs(data.damageDealt) do
        num = num + damage
      end
      if num > 0 then
        event:setCostData(self, { num = num })
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    for _, to in ipairs({ player, target }) do
      if to:isAlive() then
        to:drawCards(event:getCostData(self).num, skel.name)
      end
    end
  end,
})

return skel